package org.aurora.framework.boot.data.mybatis.configure;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Objects;

/**
 * MyBatisFlexCustomProperties
 * <pre>
 * description: MyBatis-Flex configuration custom properties
 * create date: 2025-03-13 21:37:30
 * </pre>
 *
 * @param enabled           Enable MyBatis-Flex, default to enable
 * @param showSql           Print sql script in the console，default not to print
 * @param enableAudit       Enable the audit function，default not to enabled
 * @param enableLogicDelete Enable the logic delete function，default is enabled
 * @param logicDeleteField  Logic delete field in the database, default is 'deleted'
 * @param enableTenant      Enable the tenant function，default not to enabled
 * @param tenantField       Tenant field in the database, default is 'tenant_id'
 * @param versionField      Lock version field in the database, default is 'lock_version'
 * @author cao.yong[cymsn81@126.com]
 */
@ConfigurationProperties(prefix = MyBatisFlexCustomProperties.CONFIG_PREFIX)
public record MyBatisFlexCustomProperties(
    Boolean enabled, Boolean showSql, Boolean enableAudit, Boolean enableLogicDelete, String logicDeleteField, Boolean enableTenant, String tenantField, String versionField
) {
    /**
     * Config path prefix
     */
    public static final String CONFIG_PREFIX = "aurora.mybatis.flex";

    /**
     * Custom constructor, Set default values for attributes
     */
    public MyBatisFlexCustomProperties(Boolean enabled, Boolean showSql, Boolean enableAudit, Boolean enableLogicDelete, String logicDeleteField, Boolean enableTenant, String tenantField, String versionField) {
        this.enabled = Objects.nonNull(enabled) ? enabled : true;
        this.showSql = Objects.nonNull(showSql) ? showSql : false;
        this.enableAudit = Objects.nonNull(enableAudit) ? enableAudit : false;
        this.enableLogicDelete = Objects.nonNull(enableLogicDelete) ? enableLogicDelete : true;
        this.logicDeleteField = Objects.nonNull(logicDeleteField) ? logicDeleteField : "deleted";
        this.enableTenant = Objects.nonNull(enableTenant) ? enableTenant : false;
        this.tenantField = Objects.nonNull(tenantField) ? tenantField : "tenant_id";
        this.versionField = Objects.nonNull(versionField) ? versionField : "lock_version";
    }
}
